package ua.dp.md05;

import ua.dp.md05.dao.CommentDao;
import ua.dp.md05.dao.ProductDao;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import java.util.List;

@Stateless
public class CommentTestdata {

	private static final String CONTENT = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.";

	private static final int QUANTITY = 2;

	@EJB
	private ProductDao productDao;

	@EJB
	private CommentDao commentDao;

	public void insert() {
		List<Product> products = productDao.findAll();

		for (Product product : products) {
			for (int i = 0; i < QUANTITY; i++) {
				Comment comment = new Comment();
				comment.setAuthor(product.getAuthor());
				comment.setProduct(product);
				comment.setContent(CONTENT);

				commentDao.persist(comment);
			}
		}
	}

}
